import request from '@/utils/request'

/**
 * 分页查询站点信息
 *
 * @param {*} query
 */
export function getSmskStationList(query) {
  return request({
    url: '/smsk/admin/station/list',
    method: 'get',
    params: query
  })
}

/**
 * 创建站点信息
 * @param {*} smskStationInfo
 */
export function createSmskStationInfo(smskStationInfo) {
  return request({
    url: '/smsk/admin/station/create',
    method: 'post',
    data: smskStationInfo
  })
}

/**
 * 更新站点信息
 * @param {*} smskStationInfo
 */
export function updateSmskStationInfo(smskStationInfo) {
  return request({
    url: '/smsk/admin/station/update',
    method: 'post',
    data: smskStationInfo
  })
}

/**
 * 删除站点信息
 * @param {*} id
 */
export function deleteSmskStationInfo(id) {
  return request({
    url: '/smsk/admin/station/delete',
    method: 'post',
    params: { id }
  })
}

export function selectStationList(companyId) {
  return request({
    url: '/smsk/admin/station/stationlist',
    method: 'get',
    params: { companyId }
  })
}

export function importStation(fileobj, obj) {
  if (!fileobj || !fileobj.file) {
    return {}
  }
  const param = new FormData()
  if (obj) {
    for (const key in obj) {
      param.append(key, obj[key])
    }
  }
  param.append('file', fileobj.file)
  return request({
    method: 'post',
    url: '/smsk/admin/station/importStation',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: param
  })
}

export function exportStationTemplate() {
  return request({
    url: '/smsk/admin/station/exportTemplate',
    method: 'get'
  })
}

/**
 * 获取站点账号列表
 * @param {*} stationId
 */
export function getStationAccounts(companyId, stationId) {
  return request({
    url: '/smsk/admin/station/account',
    method: 'get',
    params: { companyId, stationId }
  })
}

/**
 * 站点分配账号
 * @param {*} stationId
 * @param {*} accountIds
 */
export function updateStationAccount(stationId, accountIds) {
  return request({
    url: '/smsk/admin/station/auth',
    method: 'post',
    params: { stationId },
    data: accountIds,
    headers: { 'Content-Type': 'application/json;charset-UTF-8' }
  })
}
